<template>
  <ve-modal :title="type=='a'?'请先完善企业联系人信息，再发起签署':type=='b'?'请先完善企业联系人信息，再发起作废':'请先完善企业联系人信息，再生成电子合同'"
    v-model="visible" cancelText="关闭" :okText="type=='a'?'确认签署':type=='b'?'确认作废':'确认生成'" @close="visible = false"
    @confirm="onConfirm">
    <ve-form :model="form" ref="formRef" :rules="formRules">
      <ve-form-item label="手机号" prop="memberPhone" required>
        <ve-input v-model="form.memberPhone" :maxlength="11" />
      </ve-form-item>
      <ve-form-item label="联系人姓名" prop="linkman" required>
        <ve-input v-model="form.linkman" :maxlength="20" />
      </ve-form-item>
    </ve-form>
  </ve-modal>
</template>

<script setup>
  import {
    ref
  } from 'vue'

  const emit = defineEmits(['ok'])

  const visible = ref(false)
  const record = ref()
  const title = ref()
  const type = ref()
  const form = ref({})
  const okTexts = ('确认')
  let formRules = {
    memberPhone: [{
        required: true,
        message: '请输入手机号'
      },
      {
        len: 11,
        match: /^[0-9]+$/,
        message: '仅支持11位数字'
      },
    ],
    linkman: [{ required: true, message: '请填写联系人姓名' },],
  }

  const open = (rec, tp, clientData) => {
    console.log(rec)
    console.log(tp)
    record.value = rec
    form.value.memberPhone = clientData.mobile
    form.value.linkman = clientData.linkman
    type.value = tp //a发起签署 b发起作废 c生成合同
    visible.value = true
  }
  // 点击确认
  const formRef = ref()
  const onConfirm = () => {
    formRef.value.validate((valid) => {
      if (valid) {
        var recordData = {
          phone: form.value.memberPhone,
          linkman: form.value.linkman,
          record: record.value,
          type: type.value
        }
        console.log('recordData', recordData)
        visible.value = false
        emit('ok', recordData)
      }
    })
  }

  defineExpose({
    open,
  })
</script>
<style lang="less" scoped>
  :deep(.ve-modal-title) {
    font-size: 32rpx;
  }
</style>